package com.nc.web.controller;

import javax.annotation.Resource;

import com.alibaba.fastjson.JSON;

import com.nc.background.domain.TestDbDO;
import com.nc.background.manager.TestManager;
import com.nc.background.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author <a href="yongzhou.yyz@cainiao.com">changling</a>
 * @version 1.0
 * @since 2017/9/3
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestManager testManager;

    @Resource
    private TestMapper testMapper;

    @RequestMapping("/hello")
    public String testHello(@RequestParam("name") String name){
        return "hello:" + name + "," + testManager.testManage();
    }

    @RequestMapping("/insert")
    public void insert(@RequestParam("title") String title){
        TestDbDO testDbDO = new TestDbDO();
        testDbDO.setTitle(title);
        testMapper.insert(testDbDO);
    }

    @RequestMapping("/query")
    public String query(@RequestParam("id") long id){
        return JSON.toJSONString(testMapper.query(id));
    }
}
